package com.lfs.adapter.controller;

import com.alibaba.fastjson.JSONObject;
import com.lfs.adapter.dto.PddProductPropertyDto;
import com.lfs.adapter.service.impl.PlatformManagerServiceImpl;
import com.lfs.base.dto.Result;
import com.lfs.base.dto.ResultObject;
import com.lfs.interfaces.dto.TokenCreateDto;
import com.lfs.interfaces.dto.LogisticsTemplateDto;
import com.lfs.interfaces.model.vo.LogisticsTemplateVo;
import com.lfs.interfaces.model.vo.MallInfoVo;
import com.lfs.interfaces.model.vo.TokenCreateVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/platform")
public class PlatformManagerController {

    @Resource
    private PlatformManagerServiceImpl platformManagerService;

    /**
     * 店铺管理-添加或授权店铺
     * @param
     * @return
     */
    @RequestMapping(value = "/getAuthUrl", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> getAuthUrl(@RequestBody TokenCreateDto tokenCreateDto) {

        return ResultObject.successObject(platformManagerService.getAuthUrl(tokenCreateDto),"success");

    }

    /**
     * 店铺管理-添加或授权店铺
     * @param
     * @return
     */
    @RequestMapping(value = "/getAccessToken", method = RequestMethod.POST)
    @ResponseBody
    public Result<TokenCreateVo> getAccessToken(@RequestBody TokenCreateDto tokenCreateDto) {
        TokenCreateVo tokenCreateVo = platformManagerService.getAccessToken(tokenCreateDto);
        return ResultObject.successObject(tokenCreateVo,"success");
    }

    /**
     * 店铺管理-添加或授权店铺
     * @param
     * @return
     */
    @RequestMapping(value = "/getGoodsCats", method = RequestMethod.POST)
    @ResponseBody
    public Result<TokenCreateVo> getGoodsCats() {
        platformManagerService.getGoodsCats();
        return ResultObject.successObject(null,"success");
    }

    /**
     * 店铺管理-添加或授权店铺
     * @param
     * @return
     */
    @RequestMapping(value = "/getGoodsCatRule", method = RequestMethod.POST)
    @ResponseBody
    public Result<TokenCreateVo> getGoodsCatRule() {
        platformManagerService.getGoodsCats();
        return ResultObject.successObject(null,"success");
    }

    /**
     * 店铺管理-添加或授权店铺
     * @param
     * @return
     */
    @RequestMapping(value = "/getLogisticsTemplate", method = RequestMethod.POST)
    @ResponseBody
    public Result<List<LogisticsTemplateVo>> getLogisticsTemplate(@RequestBody LogisticsTemplateDto logisticsTemplateDto) {
        List<LogisticsTemplateVo> list =  platformManagerService.getLogisticsTemplate(logisticsTemplateDto);
        return ResultObject.successObject(list,"success");
    }

    /**
     * 根据accessToken获取店铺信息
     * @param
     * @return
     */
    @RequestMapping(value = "/getMallInfo", method = RequestMethod.POST)
    @ResponseBody
    public Result<MallInfoVo> getMallInfo(@RequestBody TokenCreateDto tokenCreateDto) {
        return ResultObject.successObject(platformManagerService.getMallInfo(tokenCreateDto),"success");
    }

    /**
     * 店铺管理-发布上架商品
     * @param
     * @return
     */
    @RequestMapping(value = "/releaseProduct", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> releaseProduct() {

        return ResultObject.successObject(platformManagerService.releaseProduct(),"success");

    }

    /**
     * 发布产品-获取当前店铺可发布商品类目
     * @param
     * @return
     */
    @RequestMapping(value = "/getCurrentCommodityCategory", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> getCurrentCommodityCategory(@RequestParam("accessToken") String accessToken) {
        String resultStr = platformManagerService.getCurrentCommodityCategory(accessToken);
        return ResultObject.successObject(resultStr,"success");
    }
    /**
     * 发布产品-查询品牌
     * @param
     * @return
     */
    @RequestMapping(value = "/searchPddBrand", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> searchPddBrand(@RequestParam("value") String value, @RequestParam("catId") Long catId, @RequestParam("refPid") Long refPid, @RequestParam("accessToken") String accessToken) {
        String resultStr = platformManagerService.searchPddBrand(value, catId, refPid, accessToken);
        return ResultObject.successObject(resultStr,"success");
    }

    /**
     * 发布产品-查询运费模板
     * @param
     * @return
     */
    @RequestMapping(value = "/getFreightTemplateData", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> getFreightTemplateData(@RequestParam("accessToken") String accessToken) {
        String resultStr = platformManagerService.getFreightTemplateData(accessToken);
        return ResultObject.successObject(resultStr,"success");
    }

    /**
     * 发布产品-关联视频
     * @param
     * @return
     */
    @RequestMapping(value = "/getVideoData", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> getVideoData(@RequestParam("accessToken") String accessToken) {
        String resultStr = platformManagerService.getVideoData(accessToken);
        return ResultObject.successObject(resultStr,"success");
    }

    /**
     * 发布产品-获取商品属性
     * @param
     * @return
     */
    @RequestMapping(value = "/getCurrentGoodsInfo", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> getCurrentGoodsInfo(@RequestParam("catId") Long catId, @RequestParam("accessToken") String accessToken) {
        String resultStr = platformManagerService.getCurrentGoodsInfo(catId, accessToken);
        return ResultObject.successObject(resultStr,"success");
    }

    /**
     * 发布产品-获取商品两件折扣属性
     * @param
     * @return
     */
    @RequestMapping(value = "/getTwoPiecesDiscountRule", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> getTwoPiecesDiscountRule(@RequestParam("catId") Long catId, @RequestParam("accessToken") String accessToken) {
        String resultStr = platformManagerService.getTwoPiecesDiscountRule(catId, accessToken);
        return ResultObject.successObject(resultStr,"success");
    }

    /**
     * 发布产品-获取商品规格
     * @param
     * @return
     */
    @RequestMapping(value = "/getGoodsSpecifications", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> getGoodsSpecifications(@RequestParam("catId") Long catId, @RequestParam("accessToken") String accessToken) {
        String resultStr = platformManagerService.getGoodsSpecifications(catId, accessToken);
        return ResultObject.successObject(resultStr,"success");
    }

    /**
     * 发布产品-自定义的规格
     * @param
     * @return
     */
    @RequestMapping(value = "/getCustomSpecifications", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> getCustomSpecifications(@RequestParam("parentSpecId")Long parentSpecId, @RequestParam("specName")String specName, @RequestParam("accessToken") String accessToken) {
        String resultStr = platformManagerService.getCustomSpecifications(parentSpecId, specName, accessToken);
        return ResultObject.successObject(resultStr,"success");
    }


    /**
     * 发布产品-商品地区/国家接口
     * @param
     * @return
     */
    @RequestMapping(value = "/getGoodsCountry", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> getGoodsCountry(@RequestParam("accessToken") String accessToken) {
        String resultStr = platformManagerService.getGoodsCountry(accessToken);
        return ResultObject.successObject(resultStr,"success");
    }

    /**
     * 发布产品-商品图片上传接口
     * @param
     * @return
     */
    @RequestMapping(value = "/goodsImgUpload", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> goodsImgUpload(@RequestParam("fileUrl") String fileUrl, @RequestParam("accessToken") String accessToken) {
        String resultStr = platformManagerService.goodsImgUpload(fileUrl, accessToken);
        return ResultObject.successObject(resultStr,"success");
    }

    /**
     * 发布产品-图片上传到图片空间
     * @param
     * @return
     */
    @RequestMapping(value = "/filesPaceImgUpload", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> filesPaceImgUpload(@RequestParam("fileUrl") String fileUrl, @RequestParam("accessToken") String accessToken) {
        String resultStr = platformManagerService.filesPaceImgUpload(fileUrl, accessToken);
        return ResultObject.successObject(resultStr,"success");
    }

    /**
     * 发布产品-商品新增接口提交发布
     * @param
     * @return
     */
    @RequestMapping(value = "/releaseGoods", method = RequestMethod.POST)
    @ResponseBody
    public Result<Map<String, Object>> releaseGoods(@RequestBody PddProductPropertyDto pddProductPropertyDto, @RequestParam("accessToken") String accessToken) {
        Map<String, Object> resultStr = platformManagerService.releaseGoods(pddProductPropertyDto, accessToken);
        return ResultObject.successObject(resultStr,"success");
    }

    /**
     * 发布产品-商品新增接口提交发布
     * @param
     * @return
     */
    @RequestMapping(value = "/getPageCode", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> getPageCode(@RequestBody JSONObject jsonObject) {
        String resultStr = platformManagerService.getPageCode(jsonObject);
        return ResultObject.successObject(resultStr,"success");
    }
}
